<template>
  <div class="topic">
     <div class="top">
        <el-form  label-width="80px">

        <el-form-item label="名称">
          <el-input v-model="queryName" placeholder="专题名称"></el-input>
         
        </el-form-item>

         <el-button type="primary" @click="queryFn">查询</el-button>
        <el-button type="primary" @click="addFn">添加</el-button>
        
       </el-form>

     </div>
     <div class="table">
       <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        prop="id"
        label="ID"
        >
      </el-table-column>
      <el-table-column
        prop="title"
        label="主标题"
        >
      </el-table-column>
      <el-table-column
        prop="price_info"
        label="起步价格"
        >
      </el-table-column>
      <el-table-column
        prop="is_show"
        label="显示"
        >
        <template slot-scope="scope">
          {{scope.row.is_show===1?'是':'否'}}
        </template>
      </el-table-column>
      <el-table-column
        label="操作">
       <template slot-scope="scope">
         <el-button type="primary" @click="editFn(scope.row.id)">编辑</el-button>
       </template>
      </el-table-column>
      </el-table>
     </div>
     <div class="footer">
       <GoodsFooter @fn="currentPageFn" @fn2="sizeFn" :total="count" :pageSizes="pageSize" :currentPage4="currentPage"/>
     </div>
  </div>
</template>

<script>
import GoodsFooter from "../good/GoodsFooter.vue"
const {getTopicLists} = require("../../request/httpApi")
export default {
  components:{
    GoodsFooter
  },
  data(){
    return {
      tableData:[{}],  //表格数据
      queryName:'',   //搜索框的值
      size:10,  
      page:1,  
      count:0,  //总条目数
      pageSize:10,  //分页 一页数量
      currentPage:1  //当前页的页数

    }
  },
  created(){
    //数据请求 渲染页面
    this.getTopicListsFn()
  },
  methods:{
    // 数据请求封装
    getTopicListsFn(){
      //专题请求的参数
         getTopicLists({
      page:this.page,
      size:this.size,
      name:this.queryName
    }).then( res=>{
      let {count,pageSize,currentPage,data} = res.data
      this.count = count
      this.pageSize=pageSize
      this.currentPage = currentPage
      this.tableData = data
      // console.log(res); 
    })
    },
   
    //分类数据 子传父
    sizeFn(val){
      this.size = val
      this.getTopicListsFn()
    },
    currentPageFn(val){
      this.page = val
       this.getTopicListsFn()
    },
    //点击查询按钮
    queryFn(){
      //搜素框的非空检验
     if(this.queryName===''){
       this.$message.error("请输入专题名称")
       return
     }
     this.getTopicListsFn()
    },
    //点击添加按钮 
    addFn(){
      this.$router.push("/addtopic")
    },
    //点击编辑按钮
    editFn(id){
      // console.log(id); 得到跳转的id
      this.$router.push(`/edittopic/${id}`)
    }

  }
}
</script>

<style lang="less">
.topic{
  background:#fff;
  padding: 10px;
  .top {
    .el-form {
        display: flex;

        .el-form-item{
          margin-bottom: 15px;

           .el-form-item__label{
      width: 50px !important;
    }
    .el-form-item__content{
      margin-left: 50px !important;
    }
    .el-input__inner {
      width: 200px;
      height: 32px;
      line-height: 32px;
    }
        }

        
    .el-button{
      margin-top: 4px;
      margin-left: 10px;
      width: 56px;
      height: 32px;
      display: flex;
      justify-content:center;
      align-items: center;
    }
    }
   
  }
  .table {
     .el-button{
      margin-top: 4px;
      margin-left: 10px;
      width: 56px;
      height: 32px;
      display: flex;
      justify-content:center;
      align-items: center;
    }
  }
  }
</style>